using Engine;
using Game;
using GameEntitySystem;

namespace SCIENEW {
    public class SteamEngineDevice : IlluminableDevice, IEntityDevice<ComponentSteamEngine>, IFluidTransferrerDevice {
        public SteamEngineDevice() : base(
            "SteamEngineDevice",
            143,
            175,
            204
        ) {
            DownSlot = 204;
        }

        public FluidTransferrer? CreateFluidTransferrer(SubsystemFluidTransfer subsystemFluidTransfer, SubsystemTerrain subsystemTerrain, int value, Point3 point) => new SteamEngineTransferrer(point, subsystemTerrain);

        public FluidConnector? GetConnector(SubsystemTerrain terrain, int value, int face, int x, int y, int z) {//侧面，背面为流体输入口
            int deviceDirection = GetDirection(value);
            DevicesUtils.GetSideFaceOfXZ(deviceDirection, out int sideFace1, out int sideFace2);
            int backFace = CellFace.OppositeFace(deviceDirection);
            if (face == backFace
                || face == sideFace2
                || face == sideFace1
                || face == 5)
                return new FluidConnector(new CellFace(x, y, z, face), FluidConnectorType.Input, 16);
            return null;
        }

        public string GetEntityName(int value) => "SteamEngine";

        public Widget GetWidget(IInventory inventory, ComponentSteamEngine component) => new SteamEngineWidget(inventory, component);

        public override DeviceBehavior[] GetBehaviors(Project project) => [new SteamEngineDeviceBehavior(project), new FluidTransferrerDeviceBehavior(project)];
    }
}